package com.dandan.tzx.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.service.SerializationService;
import com.alibaba.fastjson.JSON;
import com.dandan.tzx.model.Person;
import com.dandan.tzx.router.DDRouter;
import com.dandan.tzx.routerhelper.R;

/**
 * Created by tanzhenxing
 * Date: 2017/12/25 下午5:32
 * Description:
 */

@Route(path = ParamsCallActivity.PATH)
public class ParamsCallActivity extends BaseActivity {
    public static final String PATH = "/activity/ParamsCallActivity";
    @Autowired
    public String name;
    @Autowired
    public int age;
    @Autowired(name = "girl") // 通过name来映射URL中的不同参数xxxxxxxxx
    public boolean boy;
    @Autowired
    Person obj;    // 支持解析自定义对象，URL中使用json传递
    SerializationService serializationService;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_external_call);
        DDRouter.getInstance().inject(this);
        init();
    }

    protected void init() {
        setTitle(TAG);
        textView = (TextView) findViewById(R.id.text_view);
        textView.setText(this.getClass().getSimpleName());
        button = (Button) findViewById(R.id.button);
        serializationService = DDRouter.getInstance().navigation(SerializationService.class);
        Log.d(TAG, "param = " + name + " " + age + " " + boy + " " + serializationService.object2Json(obj));
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DDRouter.getInstance().build(MainActivity.PATH).navigation();
            }
        });
    }
}
